home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Examples / Hello / Sources / HelloFrm.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.9 KB  |  277 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                HelloFrm.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Hello.hpp"
  11.  
  12. #ifndef HELLOFRM_H
  13. #include "HelloFrm.h"
  14. #endif
  15.  
  16. #ifndef HELLOPRT_H
  17. #include "HelloPrt.h"
  18. #endif
  19.  
  20. #ifndef HELLOCMD_H
  21. #include "HelloCmd.h"
  22. #endif
  23.  
  24. // ----- Framework Layer -----
  25.  
  26. #ifndef FWUTIL_H
  27. #include "FWUtil.h"
  28. #endif
  29.  
  30. #ifndef FWPRESEN_H
  31. #include "FWPresen.h"
  32. #endif
  33.  
  34. #ifndef FWSELECT_H
  35. #include "FWSelect.h"
  36. #endif
  37.  
  38. // ----- OS Layer -----
  39.  
  40. #ifndef FWMENU_H
  41. #include "FWMenu.h"
  42. #endif
  43.  
  44. #ifndef FWEVENT_H
  45. #include "FWEvent.h"
  46. #endif
  47.  
  48. #ifndef FWALERT_H
  49. #include "FWAlert.h"
  50. #endif
  51.  
  52. // ----- Graphic Includes -----
  53.  
  54. #ifndef FWRECT_H
  55. #include "FWRect.h"
  56. #endif
  57.  
  58. #ifndef FWTXTBOX_H
  59. #include "FWTxtBox.h"
  60. #endif
  61.  
  62. #ifndef FWRECSHP_H
  63. #include "FWRecShp.h"
  64. #endif
  65.  
  66. // ----- OpenDoc Includes -----
  67.  
  68. #ifndef SOM_Module_OpenDoc_StdProps_defined
  69. #include <StdProps.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODDragItemIterator_xh
  73. #include <DgItmIt.xh>
  74. #endif
  75.  
  76. //========================================================================================
  77. // Runtime Information
  78. //========================================================================================
  79.  
  80. #ifdef FW_BUILD_MAC
  81. #pragma segment odfhello
  82. #endif
  83.  
  84. //========================================================================================
  85. // CHelloFrame class
  86. //========================================================================================
  87.  
  88. //----------------------------------------------------------------------------------------
  89. // CHelloFrame constructor
  90. //----------------------------------------------------------------------------------------
  91. CHelloFrame::CHelloFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CHelloPart* helloPart)
  92.     : FW_CFrame(ev, odFrame, presentation, helloPart)
  93. {
  94.     fHelloPart = helloPart;
  95.  
  96.     SetDroppable(ev, TRUE);
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. // CHelloFrame destructor
  101. //----------------------------------------------------------------------------------------
  102. CHelloFrame::~CHelloFrame()
  103. {
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. //    CHelloFrame::CanAcceptDrop
  108. //----------------------------------------------------------------------------------------
  109.  
  110. ODDragResult CHelloFrame::CanAcceptDrop(Environment* ev, ODDragItemIterator* dragInfo)
  111. {
  112.     ODDragResult acceptDrop = FW_CFrame::CanAcceptDrop(ev, dragInfo);
  113.  
  114.     // ----- Test for 'TEXT' also -----
  115. #ifdef FW_BUILD_MAC
  116.     if (!acceptDrop)
  117.     {
  118.         for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
  119.             if (dragSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0))    // 'TEXT' on Scrap
  120.                 return TRUE;
  121.     }
  122. #endif
  123.  
  124.     return acceptDrop;
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. //    CHelloFrame::DoMouseDown
  129. //----------------------------------------------------------------------------------------
  130.  
  131. FW_Boolean CHelloFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  132. {
  133.     FW_Boolean result = FALSE;
  134.  
  135.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE))
  136.     {
  137.         result = this->Drag(ev, theMouseEvent);
  138.     }
  139.  
  140.     return result;
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // CHelloFrame::DoMenuEvent
  145. //----------------------------------------------------------------------------------------
  146. FW_Boolean CHelloFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  147. {
  148.     FW_Boolean menuHandled = FALSE;
  149.     
  150.     switch (theMenuEvent.GetCommandID(ev))
  151.     {
  152.         case kODCommandAbout:
  153.             menuHandled = this->DoAboutBox();
  154.             break;
  155.  
  156.         default:
  157.             menuHandled = FALSE;
  158.     }
  159.     
  160.     return menuHandled;
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. // CHelloFrame::DoAdjustMenus
  165. //----------------------------------------------------------------------------------------
  166.  
  167. FW_Boolean CHelloFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  168.                                       FW_Boolean hasMenuFocus,
  169.                                       FW_Boolean isRoot)    // Override
  170. {
  171.     if (hasMenuFocus)
  172.     {
  173.         //---- Set up the About menu item ----
  174.         FW_CString32 aboutString;
  175.         fHelloPart->GetResourceString(kAboutBoxStrings, kAboutMenuString, aboutString);
  176.         menuBar->SetItemString(ev, kODCommandAbout, aboutString);
  177.         menuBar->EnableCommand(ev, kODCommandAbout, TRUE);
  178.  
  179.         //---- Set up the Edit menu items ----
  180. #ifdef FW_BUILD_MAC
  181.         menuBar->EnableCommand(ev, kODCommandPaste, HasPropertyOnClipboard(ev, kODPropContents, FW_CPart::gMacTEXTDataType));
  182. #endif
  183.     }
  184.     
  185.     return FALSE;
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. // CHelloFrame::DoAboutBox
  190. //----------------------------------------------------------------------------------------
  191.  
  192. FW_Boolean CHelloFrame::DoAboutBox()
  193. {
  194.     FW_CString32 str1, str2;
  195.  
  196.     fHelloPart->GetResourceString(kAboutBoxStrings, kHelloPartString, str1);
  197.     fHelloPart->GetResourceString(kAboutBoxStrings, kCreditString, str2);
  198.  
  199.     FW_CAlert::DoAlert(str1, str2, FW_kOK, FW_kNoteAlert, FW_kDefaultButton1, FALSE);
  200.  
  201.     return TRUE;
  202. }
  203.  
  204. //----------------------------------------------------------------------------------------
  205. // CHelloFrame::Draw
  206. //----------------------------------------------------------------------------------------
  207.  
  208. void CHelloFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  209. {
  210.     FW_CViewContext fc(ev, this, odFacet, invalidShape);
  211.     FW_CRect invalidRect;
  212.     fc.GetClipRect(invalidRect);
  213.  
  214.     FW_CRectShape::RenderRect(fc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  215.  
  216.     FW_CRect helloRect = GetBounds(ev);
  217.  
  218.     FW_CRectShape::RenderRect(fc, helloRect, FW_kFrame, FW_PInk(FW_kRGBBlack));
  219.  
  220.     // If this is a root part, draw the text centered horizontally and vertically.
  221.     // If it's an embedded part, center the text horizontally, with word wrap and clipping.
  222.     FW_TextBoxOptions options = FW_kTextBoxJustifyHCenter | FW_kTextBoxJustifyVCenter;
  223.     if (!this->IsRoot(ev))
  224.     {
  225.         options |= FW_kTextBoxWordWrap;
  226.         options |= FW_kTextBoxClipToBox;
  227.     }
  228.     FW_CTextBoxShape::RenderTextBox(
  229.         fc,
  230.         fHelloPart->GetTextData(),
  231.         helloRect,
  232.         FW_PFont(FW_kSystemFont, FW_kPlain, FW_IntToFixed(12)),
  233.         options);
  234. }
  235.  
  236. //----------------------------------------------------------------------------------------
  237. // CHelloFrame::FrameShapeChanged
  238. //----------------------------------------------------------------------------------------
  239.  
  240. void CHelloFrame::FrameShapeChanged(Environment* ev)
  241. {
  242.     FW_CFrame::FrameShapeChanged(ev);
  243.     
  244.     this->Invalidate(ev);
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    CHelloFrame::NewEditCommand
  249. //----------------------------------------------------------------------------------------
  250.  
  251. FW_CEditCommand* CHelloFrame::NewEditCommand(Environment* ev, ODCommandID commandID)
  252. {
  253.     return FW_NEW(CHelloEditCommand, (ev, commandID, fHelloPart, this));
  254. }
  255.  
  256. //----------------------------------------------------------------------------------------
  257. //    CHelloFrame::NewDragCommand
  258. //----------------------------------------------------------------------------------------
  259.  
  260. FW_CDragCommand* CHelloFrame::NewDragCommand(Environment *ev, FW_CFrame* theFrame)
  261. {
  262.     return FW_NEW(CHelloDragCommand, (ev, fHelloPart, theFrame));
  263. }
  264.  
  265. //----------------------------------------------------------------------------------------
  266. //    CHelloFrame::NewDropCommand
  267. //----------------------------------------------------------------------------------------
  268.  
  269. FW_CDropCommand* CHelloFrame::NewDropCommand(Environment* ev,
  270.                                              FW_CFrame* frame,
  271.                                              ODDragItemIterator* dropInfo, 
  272.                                              ODFacet* odFacet, 
  273.                                              const FW_CPoint& dropPoint)
  274. {
  275.     return FW_NEW(CHelloDropCommand, (ev, fHelloPart, this, dropInfo, odFacet, dropPoint));
  276. }
  277.